home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / yk211src.lha / Yak_2.11_Src / WBStartup / Beep.c < prev    next >
C/C++ Source or Header  |  1995-10-18  |  3KB  |  101 lines

  1. /*
  2.  * beep.c
  3.  *
  4.  * Ultra-simple beep, for keyclick.c
  5.  * MWS, 5/92.
  6.  *
  7.  * Hacked from audio1.c (RKM companion disks)...
  8.  * ...Copyright (c) 1990 Commodore-Amiga, Inc.
  9.  */
  10. #include <exec/types.h>         /* Some header files for system calls */
  11. #include <exec/memory.h>
  12. #include <devices/audio.h>
  13. #include <graphics/gfxbase.h>
  14. #include <clib/alib_protos.h>
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17.  
  18. #include "beep.h"               /* prototypes */
  19.  
  20. static UBYTE whichannel[] = {1, 2, 4, 8};
  21. static struct IOAudio *AIOptr;  /* Pointer to the IO block for IO commands   */
  22. static struct MsgPort *port;    /* Pointer to a port so the device can reply */
  23.  
  24. __chip UBYTE data[] = {
  25.         0xEF, 0xFB, 0xF7, 0xF7, 0x12, 0x0F, 0xDA, 0xCC, 
  26.         0x06, 0x20, 0x2A, 0x07, 0xC7, 0xB8, 0xD7, 0x15, 
  27.         0x50, 0x38, 0xF4, 0xB1, 0x86, 0xD0, 0x24, 0x4D, 
  28.         0x27, 0xEB, 0xBC, 0xAE, 0xD5, 0x0B, 0x1E, 0x08, 
  29.         0xDE, 0xC1, 0xC9, 0xF4, 0x28, 0x2C, 0x07, 0xDE, 
  30.         0xC3, 0xC6, 0xE4, 0x10, 0x20, 0x04, 0xE3, 0xD1, 
  31.         0xD9, 0xEE, 0x13, 0x24, 0x15, 0xEC, 0xD1, 0xCC, 
  32.         0xE4, 0x0B, 0x1E, 0x18, 0xF8, 0xDE, 0xD7, 0xE5, 
  33.         0xFD, 0x13, 0x1A, 0x06, 0xE9, 0xDA, 0xE1, 0xF4, 
  34.         0x08, 0x17, 0x16, 0xFB, 0xE1, 0xD4, 0xE4, 0xFD, 
  35.         0x0E, 0x15, 0x0C, 0xF1, 0xDE, 0xE0, 0xF0, 0x00
  36. };
  37.  
  38. #define SAMPLES         sizeof(data)
  39. #define DURATION        5
  40. #define FREQUENCY       270
  41. #define CLOCK           3579545         /* PAL clock - not crucial here */
  42.  
  43. void
  44. FreeAudio ()                    /* free allocated audio resources */
  45. {
  46.         if (AIOptr)
  47.         {
  48.                 FreeMem (AIOptr, sizeof (struct IOAudio));
  49.                 AIOptr = NULL;
  50.         }
  51.         if (port)
  52.         {
  53.                 DeleteMsgPort (port);
  54.                 port = NULL;
  55.         }
  56. }
  57.  
  58. BOOL
  59. AllocAudio ()                   /* allocate audio resources */
  60. {
  61.         if ((AIOptr = (void *)AllocMem (sizeof (struct IOAudio), MEMF_PUBLIC | MEMF_CLEAR)) &&
  62.             (port = CreateMsgPort ()))
  63.         {
  64.                 AIOptr->ioa_Request.io_Message.mn_ReplyPort   = port;
  65.                 AIOptr->ioa_Request.io_Message.mn_Node.ln_Pri = -100;
  66.                 return TRUE;
  67.         }
  68.         FreeAudio ();
  69.         return FALSE;
  70. }
  71.  
  72. void
  73. beep (long volume)
  74. {
  75.         static struct Message *msg;     /* Pointer for the reply message             */
  76.  
  77.         AIOptr->ioa_Request.io_Command = ADCMD_ALLOCATE;
  78.         AIOptr->ioa_Request.io_Flags = ADIOF_NOWAIT;
  79.         AIOptr->ioa_AllocKey = 0;
  80.         AIOptr->ioa_Data = whichannel;
  81.         AIOptr->ioa_Length = sizeof (whichannel);
  82.  
  83.         /** Open the audio device and allocate a channel **/
  84.         if (OpenDevice ("audio.device", 0L, (struct IORequest *) AIOptr, 0L))
  85.                 return;
  86.  
  87.         AIOptr->ioa_Request.io_Command = CMD_WRITE;
  88.         AIOptr->ioa_Request.io_Flags = ADIOF_PERVOL;
  89.         AIOptr->ioa_Data = (BYTE *)data;
  90.         AIOptr->ioa_Length = SAMPLES;
  91.         AIOptr->ioa_Period = CLOCK / (SAMPLES * FREQUENCY);
  92.         AIOptr->ioa_Cycles = (FREQUENCY * DURATION) / 1000;
  93.         AIOptr->ioa_Volume = volume;
  94.  
  95.         BeginIO ((struct IORequest *) AIOptr);
  96.         WaitPort(port);
  97.         msg = GetMsg (port);
  98.  
  99.         CloseDevice ((struct IORequest *) AIOptr);
  100. }
  101.